<template>
  <a-modal
    v-model:open="visible"
    :footer="null"
    :closable="false"
    :maskClosable="false"
    :width="400"
  >
    <div class="login-modal-content">
      <div class="login-modal-icon">
        <info-circle-outlined style="color: #1890ff; font-size: 24px;" />
      </div>
      <div class="login-modal-text">
        您还未登录，请先登录后再查看详情
      </div>
      <div class="login-modal-buttons">
        <a-button @click="handleCancel">取消</a-button>
        <a-button type="primary" @click="handleLogin">去登录</a-button>
      </div>
    </div>
  </a-modal>
</template>

<script setup lang="ts">
import { ref } from 'vue';
import { useRouter } from 'vue-router';
import { InfoCircleOutlined } from '@ant-design/icons-vue';
import useUserStore from '@/store/modules/user';

const router = useRouter();
const visible = ref(false);

const show = () => {
  visible.value = true;
};

const hide = () => {
  visible.value = false;
};

const handleCancel = () => {
  hide();
};

const handleLogin = () => {
  hide();
  router.push('/login');
};

const isLogin = async () => {
  const res = await useUserStore().isLoggedIn();
  console.log(res);
  if (!res) {
    show();
  } else {
    hide();
  }

  return res;
}

// 暴露方法给父组件使用
defineExpose({
  show,
  hide,
  isLogin
});
</script>

<style lang="scss" scoped>
.login-modal-content {
  padding: 20px 0;
  text-align: center;
  
  .login-modal-icon {
    margin-bottom: 16px;
  }
  
  .login-modal-text {
    font-size: 16px;
    color: #333;
    margin-bottom: 24px;
  }
  
  .login-modal-buttons {
    display: flex;
    justify-content: center;
    gap: 16px;
    
    .ant-btn {
      min-width: 100px;
    }
  }
}
</style> 